<?php

class BaseAccountAction extends Action {

	protected $User;
	protected $uid;
	protected $profile;
	protected $messageCount;
	protected $noticeCount;

	protected function _initialize() {
		//调试用的
		$this->uid = Session::get('user_id');
		if (array_key_exists(strtolower(MODULE_NAME), C("NOT_AUTH_MODULE"))) {
			$action = C("NOT_AUTH_MODULE." . strtolower(MODULE_NAME));
			if (empty($action) || (is_array($action) && in_array(strtolower(ACTION_NAME), $action))) {
				
			} else {
				$this->auth();
			}
		} else {
			$this->auth();
		}
	}

	public function init() {

		$this->auth();
		$this->User = D('User')->where("user_id=" . $this->uid);
		//获取用户基本信息
		$this->profile = $this->User->relation('school')->cache("user_" . $this->uid)->find();
		//获取未读私信
		$this->messageCount = D('Message')->cache("message_new_" . $this->uid)->where("(user_id=" . $this->uid . " and status=0) or (from_id=" . $this->uid . " and from_status=0)")->count();
		//获取未读提醒
		$this->noticeCount = D('Notice')->cache("notice_new_" . $this->uid)->where("user_id=" . $this->uid . " and status=0")->count();

		$this->assign('profile', $this->profile);
		$this->assign('messageCount', $this->messageCount);
		$this->assign('noticeCount', $this->noticeCount
		);
	}

	//登录状态验证
	public function auth() {
		if (empty($this->uid)) {
			redirect(__APP__ . "/account");
		}
	}

}

?>
